<?
	require_once '../inc/functions.php';
	require_once 'data.php';
	$section='Users';
	$result = Users::GetAll();
?>

<!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Users</title>
        <style type="text/css">
			.new-row { background: #CC0; }
		</style>
    </head>
    
    <body>
		<? include("../inc/tabs.php"); ?>
        <h1>Users</h1>
        <div class="error" id="msgbox"></div>
        <a href="edit.php">Add</a>
        <table>
        	<tr>
            	<th>FirstName</th>
            	<th>LastName</th>
            	<th>PictureURL</th>
            	<th>FBID</th>
            	<th>Lookup_id</th>
            </tr>
			<? while($rs = $result->fetch_assoc()){ ?>
            	<? include 'index_details.php'; ?>
            <? } ?>
            <tr>
            	<td id="insert" colspan="6">
                </td>
            </tr>
        </table>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js">
		</script>
        <script type="text/javascript">
		$(function(){
			$.get("edit.php?IsAjax=1", function(data){
				$("#insert").html(data.html);
			},"json");
			$(".AjaxLink").bind('click', LoadForm);
			$("form").live('submit', function(){
				var f = this;
				var formVars = $(this).serialize();
				$.post(this.action, formVars, function(data){
					if(data.message == "Error")
					{
						$(f).replaceWith(data.html);
						$("#msgbox").html(data.errors);
					}
					else
					{
						var tr = $(f).closest("tr");
						tr.replaceWith(data.html);
						tr.find(".AjaxLink").bind('click', LoadForm);
					}
				},"json");
				return false;
			})
		});
		function LoadForm(){
				var a = this;
				$.get(this.href, {IsAjax:true}, function(data){
					var tr = $(a).closest("tr");
					tr.find("td").hide();
					var temp = $("<td colspan='6' />").appendTo(tr);
					temp.html(data.html);
					//$("#insert").html(data);
					temp.find(".cancel").click(function(){
						temp.remove();
						tr.find("td").show();
					})
				},"json");
				return false;
			}
		</script>
    </body>
</html>

<? //$conn->close(); ?>